package com.study.common.exception;


/**
 * 业务异常基类，所有业务异常都必须继承于此异常
 */
public class BizException extends RuntimeException {

	private static final long serialVersionUID = -5875371379845226068L;

	/**
	 * 数据库操作
	 */
	public static final BizException DB_SELECT_ERROR = new BizException("900100100", "数据库select操作异常");
	
	public static final BizException DB_INSERT_ERROR = new BizException("900100200", "数据库insert操作异常");
	
	public static final BizException DB_UPDATE_ERROR = new BizException("900100300", "数据库update操作异常");
	public static final BizException DB_UPDATE_ERROR_0 = new BizException("900100301", "数据更新条数为零");

	public static final BizException DB_DELETE_ERROR = new BizException("900100400", "数据库delete操作异常");
	
	public static final BizException DB_GET_SEQ_NEXT_VALUE_ERROR = new BizException("900100500", "数据库获取序列操作异常");

	/**
	 * 数据类型转换异常
	 */
	public static final BizException DT_CHANGE_ERROR = new BizException("900100600", "数据类型转换异常");
	public static final BizException DT_CHANGE_ERROR_OBJTOINT = new BizException("900100601", "数据类型转换异常,Object转换int操作异常");
	
	/**
	 * 订单支付异常
	 */
	public static final BizException ORDER_PAY_ERROR = new BizException("900100700", "订单支付异常");
	public static final BizException ORDER_PAY_ERROR_NOALLOW = new BizException("900100701", "订单状态不是待支付状态，不允许支付");
	public static final BizException ORDER_PAY_ERROR_WRONGMONEY = new BizException("900100702", "订单金额不正确，请确定后再支付");
	public static final BizException ORDER_PAY_ERROR_NOORDER = new BizException("900100703", "不存在订单");
	public static final BizException ORDER_PAY_ERROR_ORDERNUMBER = new BizException("900100704", "订单流水号生成失败");
	public static final BizException ORDER_PAY_ERROR_NOORDERNUMBER = new BizException("900100705", "订单流水号未生成");
	public static final BizException ORDER_PAY_ERROR_UPDATESTATUS = new BizException("900100706", "支付时修改订单状态失败");
	
	/**
	 * 参数为空异常
	 */
	public static final BizException PARAM_NULL_ERROR = new BizException("900100800", "参数为空");
	public static final BizException PARAM_NULL_ERROR_VERIFICATIONCODE = new BizException("900100801", "验证码不能为空");
	public static final BizException PARAM_NULL_ERROR_VERIFICATIONCODEERROR = new BizException("900100802", "验证码错误");
	
	/**
	 * 特惠活动异常
	 */
	//特惠活动次数超出限制
	public static final BizException SPECIAL_PROMOTIONS_NO_BUY_COUNT = new BizException("900100900", "特惠活动已超出该活动最高使用数量限制");
	//特惠活动超出单日购买数量
	public static final BizException SPECIAL_PROMOTIONS_NO_DAY_BUY_COUNT = new BizException("900100901", "特惠活动已超出该活动单日购买数量限制");
	//特惠活动超出单次否买数量
	public static final BizException SPECIAL_PROMOTIONS_NO_ONE_BUY_COUNT = new BizException("900100902", "特惠活动已超出该活动单次购买数量限制");
	//特惠活动超出单人购买数量
	public static final BizException SPECIAL_PROMOTIONS_NO_USER_BUY_COUNT = new BizException("900100903", "特惠活动已超出该活动单人购买数量限制");
	//特惠活动在单个商户已超出最高使用数量限制
	public static final BizException SPECIAL_PROMOTIONS_NO_STORE_BUY_COUNT = new BizException("900100904", "特惠活动在该商户已超出购买数量限制");
	//此商户无法使用该优惠
	public static final BizException SPECIAL_PROMOTIONS_NO_STORE = new BizException("900100905", "此商户无法使用该特惠活动");
	//特惠活动未包含此项优惠！
	public static final BizException SPECIAL_PROMOTIONS_NO_THIS = new BizException("900100906", "特惠活动未包含此项优惠！");
	//此优惠活动不存在
	public static final BizException SPECIAL_PROMOTIONS_NO_EXIST = new BizException("900100907", "特惠活动未包含此项优惠");
	//特惠活动已被移除
	public static final BizException SPECIAL_PROMOTIONS_IS_DELETE = new BizException("900100908", "特惠活动已被移除");
	//特惠超出有效期
	public static final BizException SPECIAL_PROMOTIONS_OUT_INDATE = new BizException("900100909", "特惠超出有效期");
	//特惠查询异常
	public static final BizException SPECIAL_PROMOTIONS_SELECT_ERROR = new BizException("900100910", "特惠查询异常");
	
	/**
	 * 普惠活动异常
	 */
	//优惠已超出最高使用数量限制
	public static final BizException PROMOTIONS_OFFERS_NO_BUY_COUNT = new BizException("900101000", "优惠已超出最高使用数量限制");
	//此优惠活动无法使用
	public static final BizException PROMOTIONS_OFFERS_ERROR = new BizException("900101001", "此优惠活动无法使用");
	//超出单日优惠次数上限
	public static final BizException PROMOTIONS_OFFERS_NO_DAY_BUY_COUNT = new BizException("900101002", "超出单日优惠次数上限");
	//商户买单名额已抢光
	public static final BizException PROMOTIONS_OFFERS_NO_STORE_BUY_COUNT = new BizException("900101003", "该商户买单名额已抢光");
	//优惠活动不存在
	public static final BizException PROMOTIONS_OFFERS_NO_EXIST = new BizException("900101004", "优惠活动不存在");
	//暂无此类型促销
	public static final BizException PROMOTIONS_OFFERS_TYPE_ERROR = new BizException("900101005", "暂无此类型促销");
	
	/**
	 * 积分、红包异常
	 */
	//积分金额计算有误
	public static final BizException INTEGRAL_MONEY_ERROR = new BizException("900101100", "积分金额计算有误");
	//红包使用错误
	public static final BizException RED_PACKET_USE_ERROR = new BizException("900101101", "红包使用错误");
	//红包金额计算错误
	public static final BizException RED_PACKET_MONEY_ERROR = new BizException("900101102", "红包金额计算错误");
	/**
	 * 下单类异常
	 */
	//订单金额计算有误
	public static final BizException ORDER_AMOUNT_ERROR = new BizException("900101200", "金额计算有误");
	//该订单不允许使用红包
	public static final BizException ORDER_CANNOR_USR_RED_PACKET = new BizException("900101201", "该订单不允许使用红包");
	//该订单不允许使用积分
	public static final BizException ORDER_CANNOR_USR_INTEGRAL = new BizException("900101202", "该订单不允许使用积分");
	//订单优惠金额不一致（手机端和后台）
	public static final BizException ORDER_DISCOUNT_MONEY_ERROR = new BizException("900101203", "订单优惠金额不一致");
	//订单实付金额不一致
	public static final BizException ORDER_GATHERING_MONEY_ERROR = new BizException("900101204", "订单实付金额不一致");
	//买单订单金额为零,为0不能下单
	public static final BizException ORDER_TOTALAMOUNT_IS_ZERO = new BizException("900101205", "买单订单金额为零");
	
	
	/**
	 * 商品类异常
	 */
	//商品超出销售时间
	public static final BizException PRODUCT_NO_IN_SALE_TIME = new BizException("900101300", "商品超出销售时间");
	//商品数据有变更，请重新选购商品
	public static final BizException PRODUCT_INFO_CHANGE = new BizException("900101302", "商品数据有变更，请重新选购商品");
	//特卖会中未包含该商品
	public static final BizException PRODUCT_NO_IN_SHOPPING = new BizException("900101303", "特卖会中未包含该商品");
	//商品查询失败
	public static final BizException PRODUCT_SELECT_ERROR = new BizException("900101304", "商品查询失败");
	//查询商品限购时间失败
	public static final BizException PRODUCT_SELECT_LIMIT_TIME_ERROR = new BizException("900101305", "查询商品限购时间失败");
	//不存在该商品
	public static final BizException NO_PRODUCT = new BizException("900101306", "不存在该商品");
	//商品超出单人购买数量
	public static final BizException PRODUCT_NO_USER_BUY_COUNT = new BizException("900101303", "商品超出单人购买数量");
	
	/**
	 * 商户类异常
	 */
	//系统错误：未查到商家信息
	public static final BizException NO_STORE_INFO = new BizException("900101400", "系统错误：未查到商家信息");
	
	/**
	 * 特卖会类异常
	 */
	//查询特卖会已经购买总数量失败
	public static final BizException SHOPPING_SALE_COUNT_SELECT_ERROR = new BizException("900101500", "查询特卖会已经购买总数量失败");
	//超出特卖会限制购买数量
	public static final BizException SHOPPING_NO_BUY_COUNT = new BizException("900101501", "超出特卖会限制购买数量");
	//特卖会查询单日已经购买数量失败
	public static final BizException SHOPPING_DAY_BUY_COUNT_SELECT_ERROR = new BizException("900101502", "特卖会查询单日已经购买数量失败");
	//特卖会超出有效期
	public static final BizException SHOPPING_NO_IN_SALE_TIME = new BizException("900101503", "特卖会超出有效期");
	//特卖会超过单笔购买上限啦，请重新下单
	public static final BizException SHOPPING_NO_ONE_BUY_COUNT = new BizException("900101504", "超过单笔购买上限啦，请重新下单");	
	//特卖会超过单日购买上限啦，下次再来吧
	public static final BizException SHOPPING_NO_DAY_BUY_COUNT = new BizException("900101505", "超过单日购买上限");	
	
	/**
	 * 订单验证异常
	 */
	//不存在该订单
	public static final BizException NO_THIS_ORDER = new BizException("900101600", "不存在该订单");
	//订单状态不正确
	public static final BizException ORDER_STATUS_ERROR = new BizException("900101601", "订单状态不正确");
	//验证商户id为空
	public static final BizException ORDER_STORE_ID_NULL = new BizException("900101602", "验证商户id为空");
	//该订单不能在此商户验证
	public static final BizException ORDER_NO_THIS_STORE = new BizException("900101603", "该订单不能在此商户验证");
	
	/**
	 * 异常信息
	 */
	protected String msg;

	/**
	 * 具体异常码
	 */
	protected String code;

	public BizException(String code, String msgFormat, Object... args) {
		super(String.format(msgFormat, args));
		this.code = code;
		this.msg = String.format(msgFormat, args);
	}

	public BizException() {
		super();
	}

	public String getMsg() {
		return msg;
	}

	public String getCode() {
		return code;
	}

	/**
	 * 实例化异常
	 * 
	 * @param msgFormat
	 * @param args
	 * @return
	 */
	public BizException newInstance(String msgFormat, Object... args) {
		return new BizException(this.code, msgFormat, args);
	}

	public BizException(String message, Throwable cause) {
		super(message, cause);
	}

	public BizException(Throwable cause) {
		super(cause);
	}

	public BizException(String message) {
		super(message);
	}
}
